package com.flyee.controller.timer{
	
	import com.flyee.model.Monster;
	
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	public class MonsterTimer extends Timer {
		
		public var monster : Monster;
		
		public var checkFn : Function;
		
		public var attackFn : Function;
		
		public var trackFn : Function;
		
		public function MonsterTimer(delay:Number, repeatCount:int=0) {
			super(delay, repeatCount);
			this.addEventListener(TimerEvent.TIMER, timeHandler);
		}
		
		public function timeHandler(event : TimerEvent) : void {
			var action : int = checkFn(monster); 
			switch(action) {
				case -1 :
					//超出距离或对方死亡等
					stop();
					monster.target = null;
					break;
				case 0 : 
					//处于攻击范围内
					attackFn(monster);
					break;
				case 1 :
					//处于攻击范围外，追踪范围内
					trackFn(monster);
					break;
				case 2 :
					stop();
					monster.target = null;
					break;
				default :
					break;
			} 
			this.reset();
			this.start();
//			trace("monster action : " + action);
		}
		
		public function dispose() : void {
			this.stop();
			this.monster = null;
			this.checkFn = null;
			this.trackFn = null;
			this.attackFn = null;
		}
		
	}
}